using System;
using System.IO;
using System.Net.Mime;
using WeShare.WeiXin.Pay;
using Newtonsoft.Json;
using System.Threading;
using WeShare.WeiXin.Applet.Qr;
using WeShare.WeiXin.Applet.Qr.Entity;
using WeShare.WeiXin.Common;
using System.Collections.Generic;
using WeShare.WeiXin.Mp.Card;
using WeShare.WeiXin.Mp.Card.Entity;
using WeShare.WeiXin.Common.EnumKey;
using WeShare.WeiXin.Mp.UserManage;
using WeShare.WeiXin.Mp.MsgEntity;
using System.Xml.Linq;
using System.Diagnostics;
using System.Linq;
using WeShare.WeiXin.Mp.CustomService;
using WeShare.WeiXin.Mp.CustomService.Entity;
using WeShare.WeiXin.Mp.GroupSend;
using WeShare.WeiXin.Mp.MaterialLib;
using WeShare.WeiXin.Mp.TemplateNotice.Entity;
using static WeShare.WeiXin.Mp.Card.Entity.MemberInfo;
using WeShare.WeiXin.Mp.Menu;
using WeShare.WeiXin.Mp.Menu.Entity;
using WeShare.WeiXin.Mp.Poi;
using WeShare.WeiXin.Mp.TemplateNotice;
using WeShare.WeiXin.Mp.UserManage.Entity;
using WeShare.WeiXin.Pay.EnumKey;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var api = new OpenApi(null, errMsg =>
            {
                Console.Write(errMsg);
            });
            //http://soeasy.51vip.biz
          
            api.RegisterPay(new PayConfig { AppId = "appid", CertPath = @"C:\Users\billsking\Downloads\WXCertUtil\WXCertUtil-1.1\cert\1240050702_20181222_cert\apiclient_cert.p12", MchId = "mchid", PayKey = "paykey" });
            var rrr = PayApi.Refund(new RefundReq()
            {
                refund_desc = "测试",
                total_fee = 251,
                notify_url = "http://soeasy.51vip.biz/api/Wx/RefundNotify",
                out_trade_no = "636803057997445386",
                out_refund_no = "323d3333332323",
                refund_fee = 1,
                refund_account = RefundAccount.REFUND_SOURCE_RECHARGE_FUNDS,
            });
            // var a = PayApi.ScanPayUrl(new ScanPayReq { product_id = "32323233333" }, true);
            //var order = PayApi.QueryOrderInfo(new QueryOrderReq
            //{

            //    out_trade_no = "636803057997445386"
            //});
            //var unife = PayApi.UnifiedOrder(new UnifiedReq
            //{
            //    body = "ccee",
            //    notify_url = "http://www.baidu.com",
            //    product_id = "122",
            //    out_trade_no = "123123qq",
            //    spbill_create_ip = "172.0.0.1",
            //    total_fee = 1,
            //    trade_type = TradeType.NATIVE,
            //});
            //var close = PayApi.CloseOrder(new CloseOrderReq {out_trade_no = "123123qq"});
            // var refund = PayApi.Refund(new RefundReq { out_trade_no = "636803057997445386", total_fee = 251, refund_account = RefundCccount.REFUND_SOURCE_RECHARGE_FUNDS, refund_fee = 2, out_refund_no = "f3232378453343" });
            var query = PayApi.QueryRefundOrder(new QueryRefundOrderReq { out_trade_no = "636803057997445386" });
            return;
            #region 创建菜单
            var qm = MenuApi.Get();
            return;
            var res = MenuApi.Create(new List<ButtonInfo>
            {
                new ButtonInfo
                {
                    appid = "wxf60b766fde6fca40",
                    name = "小程序",
                    type = MenuType.miniprogram,
                    pagepath = "pages/reg/reg",
                    url = "http://qq.com"
                },
                new ButtonInfo
                {
                    type = MenuType.click,
                    key = "cc",
                    name = "签到"
                },
                new ButtonInfo
                {
                    type = MenuType.click,
                    key = "c3c",
                    name = "签到3"
                }

            });
            Console.WriteLine(res.errmsg);
            return;
            #endregion

            var logo = CardApi.UploadImgAsync(@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1541507517659&di=6bd69161682a920794ea7fdb640029ff&imgtype=0&src=http%3A%2F%2Fpic.qiantucdn.com%2F58pic%2F18%2F07%2F28%2F05e58PICHP2_1024.jpg");
            logo.Wait();
            var s = logo.Result;
            ////设置白名单
            //var r = CardApi.SetTestWhiteList(null, new List<string> { "z18702711053" });
            //var aa = CardApi.CreateQr(new SingleCardParam
            //{
            //    card_id = "pR19Cs7xLCC-BGXkYtctEUkumMnE",
            //    is_unique_code = false,
            //});
            //var box = CardApi.CreatePage(new LandingPage
            //{
            //    banner = "https://mmbiz.qpic.cn/mmbiz_jpg/BzGd2zNHkaHotSLzGicN6wLOzdFPTyhCkYNSJvTF0mMeFnfN7CgJwibs54jFNSfbYpmGvQync4SS5GhKCrqeibBDw/0",
            //    can_share = true,
            //    card_list = new List<LandingPage.CardInfo>
            //       {
            //            new LandingPage.CardInfo
            //            {
            //                 card_id="pR19Cs7xLCC-BGXkYtctEUkumMnE",
            //                  thumb_url="https://mmbiz.qpic.cn/mmbiz_jpg/BzGd2zNHkaHalgK81iaX7q4icJlkdr8iaqKhZeo2IwmuNoWLhI8UGoEBBibpII7o99QTGA8OCnYE4yrwphAvAZ5S5Q/0"
            //            }
            //       },
            //    page_title = "锦鲤驾到",
            //    scene = CardScene.SCENE_H5
            //});
            var aaa = CardApi.Create(new DiscountCard
            {
                discount = new DiscountInfo
                {
                    discount = 10,
                    base_info = new BaseInfo
                    {
                        brand_name = "阿狸小妹",
                        can_give_friend = true,
                        can_share = true,
                        center_sub_title = "中心子标题",
                        center_title = "立即使用",
                        center_url = "http://www.51soeasy.cn",
                        code_type = CodeType.CODE_TYPE_BARCODE,
                        date_info = new DateInfo
                        {
                            type = CardDateType.DATE_TYPE_FIX_TERM,
                            fixed_begin_term = 0,
                            fixed_term = 10
                        },
                        description = "这是描述",
                        get_limit = 2,
                        logo_url = "https://mmbiz.qpic.cn/mmbiz_jpg/BzGd2zNHkaHalgK81iaX7q4icJlkdr8iaqKhZeo2IwmuNoWLhI8UGoEBBibpII7o99QTGA8OCnYE4yrwphAvAZ5S5Q/0",
                        need_push_on_view = true,
                        notice = "请出示二维码",
                        service_phone = "18702711933",
                        sku = new Sku
                        {
                            quantity = 1000,
                        },
                        title = "超级折扣券",
                        use_all_locations = true,
                        use_limit = 1
                    }
                }
            });

            //var a = CardApi.UpdateMemberCard(new MemberCard
            //{
            //    member_card = new MemberInfo
            //    {
            //        background_pic_url = "http://mmbiz.qpic.cn/mmbiz_jpg/BzGd2zNHkaHotSLzGicN6wLOzdFPTyhCkYNSJvTF0mMeFnfN7CgJwibs54jFNSfbYpmGvQync4SS5GhKCrqeibBDw/0",
            //        auto_activate = true,
            //        balance_rules = "充值100送200",
            //        base_info = new BaseInfo
            //        {
            //            can_give_friend = true,
            //            can_share = true,
            //            center_sub_title = "买单可积分抵现0",
            //            center_title = "快速买单0",
            //            code_type = CodeType.CODE_TYPE_TEXT,
            //            color = CardColor.Color050,
            //            custom_url = "http://www.baidu.com",
            //            custom_url_name = "会员卡案",
            //            custom_url_sub_title = "玩转会员卡0",
            //            brand_name = "手易云",
            //            date_info = new DateInfo
            //            {
            //                type = CardDateType.DATE_TYPE_FIX_TERM,
            //                fixed_begin_term = 0,
            //                fixed_term = 5000
            //            },
            //            sku = new Sku
            //            {
            //                quantity = 100000,
            //            },
            //            description = "这是会员卡描述0",
            //            get_limit = 1,
            //            logo_url = "http://mmbiz.qpic.cn/mmbiz_jpg/BzGd2zNHkaHalgK81iaX7q4icJlkdr8iaqKhZeo2IwmuNoWLhI8UGoEBBibpII7o99QTGA8OCnYE4yrwphAvAZ5S5Q/0",
            //            need_push_on_view = true,
            //            notice = "消费时，请出示此会员卡0",
            //            promotion_url = "http://www.baidu.com",
            //            promotion_url_name = "更多优惠0",
            //            promotion_url_sub_title = "很多0",
            //            service_phone = "18702711053",
            //            title = "手易云VIP1",
            //        },
            //        balance_url = "http://www.baidu.com",
            //        bonus_cleared = "年底清零",
            //        bonus_rule = new BonusRule
            //        {
            //            cost_bonus_unit = 200,
            //            cost_money_unit = 100,
            //            increase_bonus = 1,
            //            init_increase_bonus = 100,
            //            least_money_to_use_bonus = 88,
            //            max_increase_bonus = 200,
            //            max_reduce_bonus = 500,
            //            reduce_money = 100,
            //        },
            //        bonus_rules = "这是积分规则",
            //        bonus_url = "http://www.baidu.com",
            //        discount = 90,
            //        prerogative = "精选会员卡特权",
            //        supply_balance = true,
            //        supply_bonus = true,
            //        advanced_info = new AdvancedInfo
            //        {
            //            @abstract = new Abstract
            //            {
            //                icon_url_list = new string[] { "http://mmbiz.qpic.cn/mmbiz_jpg/BzGd2zNHkaHotSLzGicN6wLOzdFPTyhCkYNSJvTF0mMeFnfN7CgJwibs54jFNSfbYpmGvQync4SS5GhKCrqeibBDw/0" },
            //                @abstract = "微信餐厅推出多种新季菜品，期待您的光临3333",
            //            },
            //            text_image_list = new List<TextImage>
            //             {
            //                  new TextImage
            //                  {
            //                       image_url ="http://mmbiz.qpic.cn/mmbiz/p98FjXy8LacgHxp3sJ3vn97bGLz0ib0Sfz1bjiaoOYA027iasqSG0sjpiby4vce3AtaPu6cIhBHkt6IjlkY9YnDsfw/0",
            //                        text="此菜品精选食材，以独特的烹饪方法，最大程度地刺激食 客的味蕾3333",
            //                  }
            //             }
            //        }
            //    }
            //});
        }
    }
}
